package com.cherry.sdk.http

import retrofit2.Retrofit

/**
 * @author 董棉生(dongmiansheng@parkingwang.com)
 * @since 18-11-14
 */

object ApiService {

    private val services = HashMap<Class<*>, Any?>()

    private lateinit var retrofit: Retrofit

    fun setRetrofit(retrofit: Retrofit) {
        this.retrofit = retrofit
    }

    fun <T> create(clz: Class<T>): T {
        var obj = services[clz]
        if (obj == null || clz !== obj.javaClass) {
            obj = retrofit.create(clz)
            services[clz] = obj
        }
        return clz.cast(obj)
    }


}